Documentation > CMS Template API Library > Asset > GetContentFields(List[String])

GetContentFields

Gets a dictionary of fields dependending on the fieldNames argument. This function is called on the current asset for all templates before running to load all DB fields. Will look for both fields equaling the name and equaling "upload#" plus the name unless the specified name already starts with upload#. If you don't provide this param, or pass null, or pass an empty list or pass a list that contains a * element, then all fields in the db are returned. Found fields are added to this asset instance's cache so there will be no more DB hits when you access them. If the optional to load all fields is taken, then any other fields lookups on the asset instance will not go back to the DB.

public IDictionary<String,String> GetContentFields(List[String])


Returns

An interface into a dictionary holding key value pairs of the data that the method was able to retrieve.

Parameters

NameDescriptionType
fieldNames Optional: Specifies the fields to return. Defaults to null. List<String>

Code Example

C#

Sample:
Asset myAsset = Asset.Load("/PathTo/Asset");
if(myAsset.IsLoaded)
{
  List<string> fieldNames = new List<string>();
  fieldNames.Add("field");

  IDictionary<string, string> fields = myAsset.GetContentFields(fieldNames);
  foreach(KeyValuePair<string, string> kvp in fields)
  {
    Out.WriteLine("Key: " + kvp.Key + "<br />");
    Out.WriteLine("Value: " + kvp.Value + "<br />");		
  }
}

Connect with Crownpeak